﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using DevWeb.Biztalk.DeploymentSettings.DeploymentService.Contracts;

namespace DevWeb.Biztalk.DeploymentSettings.DeploymentService.ClientProxy.ChannelPattern
{
    public class ProxyClient<T>
    {
        public EndpointAddress EndpointAddress { get; set; }
        public Binding Binding { get; set; }
        public T Client { get; set; }
        public ChannelFactory<T> ClientChannelBase { get; set; }

        public ProxyClient(string endpointconfigurationame)
        {

            ClientChannelBase = new ChannelFactory<T>(endpointconfigurationame);
            Client = ClientChannelBase.CreateChannel();
        }

        public ProxyClient(EndpointAddress endpointaddress, Binding binding)
        {
            if (endpointaddress == null)
                throw new ArgumentException("No Endpoint", "endpointaddress");
            if (binding == null)
                throw new ArgumentException("No binding", "binding");
            EndpointAddress = endpointaddress;
            Binding = binding;
            ClientChannelBase = new ChannelFactory<T>(Binding, EndpointAddress);
            Client = ClientChannelBase.CreateChannel();
        }

        /// <summary>
        /// Client with WsHttp binding and mode Security.None
        /// </summary>
        /// <param name="endpointaddress"></param>
        public ProxyClient(EndpointAddress endpointaddress)
            : this(endpointaddress, new WSHttpBinding(SecurityMode.None))
        {
        }
    }
}